local sk__caiyu = fk.CreateSkill {

  name = "sk__caiyu",

  tags = {  },

}



sk__caiyu:addEffect(fk.EventPhaseStart, {
  name = "sk__caiyu",
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__caiyu.name) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__caiyu.name, nil, "#sk__caiyu-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if player.dead then return end
    local generals = {}
    for name, general in pairs(Fk.generals) do
      if general.package.extensionName ~= "hegemony" and
        table.find({"zhugeliang", "wolong"}, function(s)
          return name:endsWith(s)
        end) then
        table.insert(generals, general)
      end
    end
    if #generals == 0 then return end
    local skills = {}
    for _, general in ipairs(generals) do
      local list = general:getSkillNameList(true)
      for _, skill in ipairs(list) do
        if not player:hasSkill(skill, true) then
          table.insertIfNeed(skills, skill)
        end
      end
    end
    if #skills == 0 then return end
    room:handleAddLoseSkills(player, table.random(skills), nil, true, false)
  end,
})

return sk__caiyu